<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .router-link-active{
      color: rgb(231, 86, 29);
    }
  </style>
</head>
<body>
  <div id="app">
    <router-link to="/" custom v-slot="{ navigate, href, route }">
      <button @click="navigate">首页</button>
    </router-link>
    <router-link to="/news">新闻页</router-link>
    <router-link to="/about" replace>关于我们页</router-link>
    <hr>
    <!-- 视图上定义 router-view 作为路由组件的出口 -->
    <router-view></router-view>
  </div>
  <script src="./vue.global.js"></script>
  <script src="./vue-router.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp();
    // 定义好路由组件的 config
    const HomePage = {
      template: `
        <div>
          <h1>这是首页</h1>  
        </div>
      `
    }
    const NewsPage = {
      template: `
        <div>
          <h1>这是新闻页</h1>  
        </div>
      `
    }
    const AboutPage = {
      template: `
        <div>
          <h1>这是关于我们页</h1>  
        </div>
      `
    }
    // 创建路由实例
    const routes = [
      // 单个路由规则 至少有两个属性  path 路径 component 当前路由对应路由组件
      {
        path: '/',
        component: HomePage
      },
      {
        path: '/news',
        component: NewsPage
      },
      {
        path: '/about',
        component: AboutPage
      }
    ]
    const router = VueRouter.createRouter({
      // 路由模式，这里使用的是hash 模式
      history: VueRouter.createWebHashHistory(),
      // 路由规则
      routes
    })
    // 使用路由插件
    app.use(router);
    app.mount('#app')
   
  </script>
</body>
</html>